<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/article/CategoryUtil.class.php
 *
 * 文章分类的管理类
 *
 * PHP Version 5
 *
 * @package:   class.article
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: CategoryUtil.class.php,v 1.1 2006-09-24 14:38:33 ghw Exp $
 * @date:      $Date: 2006-09-24 14:38:33 $
 */


//包含需要使用的函数
include_once FUNCTION_PATH.'utf8_substr.fun.php';

class CategoryUtil {

   /**
    * 取得排在前面的文章分类，也即
    * 热门分类
    * @param:  &$db 数据库连接
    * @return: &categroy
    * @access: public
    * @static
    */
   public static function &getTopCategory(&$db) {/*{{{*/
      $sql = 'select id, tags  from article_tags order by article_number desc limit 15 offset 0';

      $sth = $db->prepare($sql);
      $res = $db->CacheExecute(1200, $sth);

      $category = array();

      while ( $rows = $res->FetchRow() ) {
         $category[] = array(
            'id'=>$rows['id'],
            'name'=>$rows['tags'],
            'sname'=>utf8_substr($rows['tags'], 0, 9),
         );
      }

      return $category;
   }/*}}}*/


   /**
    * 取得指定文章分类的信息
    * @param:  &$db 数据库的连接
    * @return: $catagory_info 包含文章分类的信息数组（id和名字)
    * @access: public
    * @static
    */
   public static function &getInformation(&$db, $id) {/*{{{*/

      $sql = 'select id, tags as name from article_tags where id=?';
      $sth = $db->prepare($sql);
      $res = $db->CacheExecute(3600, $sth, array($id));
      $rows = $res->FetchRow();

      $catagory_info = array();

      $catagory_info['id'] = $rows['id'];
      $catagory_info['name'] = $rows['name'];

      return $catagory_info;
   }/*}}}*/

   /**
    * 取得所有的文章分类
    * @param:  &$db
    * @return: $catagory
    * @access: public
    * @static
    */
   public static function getAllCatagoryInfo(&$db) {/*{{{*/
      $sql = 'select id, tags  from article_tags order by article_number desc ';

      $sth = $db->prepare($sql);
      $res = $db->CacheExecute(3600, $sth);

      $category = array();

      while ( $rows = $res->FetchRow() ) {
         $category[] = array(
            'id'=>$rows['id'],
            'name'=>$rows['tags'],
            'sname'=>utf8_substr($rows['tags'], 0, 20),
         );
      }

      return $category;
   }/*}}}*/

   /**
    * 判断Catagory是否存在
    * @param:  &$db
    * @param:  $id 文章分类的id
    * @return: $isExists Boolean
    * @access: public
    * @static
    */
   public static function isExists(&$db, $id) {/*{{{*/
      
      $sql = 'select count(*) as num from article_tags where id=?';
      $sth = $db->prepare($sql);
      $res = $db->Execute($sth, array($id));
      $rows = $res->FetchRow();

      if ( $rows['num'] ) {
         return true;
      } else {
         return false;
      }
   }/*}}}*/






}


?>
